/*  File Name	: Sock.h
 *  Author		: Pang Jiacai
 *	 E-mail		: 823960168@qq.com
 *  Created on	: 2012-4-20
 *  Description:
 */

#ifndef SOCK_H_
#define SOCK_H_

#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>

class Sock
{
public:
	Sock();

	Sock(int pro_family,int type,int protocol,bool reuseaddr);

	virtual ~Sock();

	int open(int pro_family,int type,int protocol,bool reuseaddr);

	int close(void);

	int set_sockopt(int level,int option,void *optval,int optlen);

	const int get_sockopt(int level,int option,void *optval,int *optlen);

	int get_remote_addr(sockaddr_in *addr) const;

	int get_local_addr(sockaddr_in *addr) const;

	std::string get_host(void) const;

	int get_port(void) const;

	int enable(int flag);

	int disable(int flag);

	void set_handle(int handle);

	int get_handle(void) const;

private:
	int handle_;
};

#endif /* SOCK_H_ */
